package com.qk.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.dto.ActivityDto;
import com.qk.entity.Activity;
import com.qk.service.ActivityService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/activities")
public class ActivityController {
    @Autowired
    private ActivityService activityService;
    @GetMapping
    public Result list(ActivityDto activityDto){
        log.info("用户列表查询:{}",activityDto);
        PageResult<Activity> activityList=activityService.list(activityDto);
        return Result.success(activityList);
    }

    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id){
        log.info("用户删除:{}",id);
        activityService.delete(id);
        return Result.success();
    }

    @PostMapping
    public Result add(@RequestBody Activity activity){
        log.info("用户添加:{}",activity);
        activityService.add(activity);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id){
        log.info("用户查询:{}",id);
        Activity activity =activityService.getById(id);
        return Result.success(activity);
    }

    @PutMapping
    public Result update(@RequestBody Activity activity){
        log.info("用户修改:{}",activity);
        activityService.update(activity);
        return Result.success();
    }

    @GetMapping("/type/{type}")
    public Result getList(@PathVariable Integer type){
        log.info("用户查询:{}",type);
        List<Activity> list =activityService.getList(type);
        return Result.success(list);
    }
}
